package com.dc.designPattern._23_specification.impl.step1;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * Description: 用户实现接口
 * @author: gdc
 * @date: 2021/8/20
 * @version 1.0
 */
public class UserProvider implements IUserProvider {

    private List<User> userList;

    public UserProvider(List<User> userList) {
        this.userList = userList;
    }

    @Override
    public List<User> listByName(String name) {
        return userList.stream()
                .filter(user -> Objects.equals(user.getName(), name))
                .collect(Collectors.toList());
    }

    @Override
    public List<User> listByAgeThan(int age) {
        return userList.stream()
                .filter(user -> user.getAge() > age)
                .collect(Collectors.toList());
    }
}
